import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'
import { DNavBar } from '@/components'
import './advancefund.scss'
import http from '@/api'
import sdk from '@/common/sdk'
const bgImages = require('../assets/bgImages.png');
export default class advancefundBox extends Component {

  constructor(props) {
    super(props)
    this.state = {
      title: '车辆代购',
      list1: [
        {
          img: require("../assets/register.png"),
          text: '代购申请',
          url: '/pages/advanceform/advanceform?type=usercar'
        },
        // {
        //     img: require("../assets/order.png"),
        //     text: '库融申请',
        //     url: '/pages/financingapplication/financingapplication'
        // },
        {
          img: require("../assets/quota.png"),
          text: '额度记录',
          url: '/pages/financingrecord/financingrecord'
        },
        {
          img: require("../assets/inventory.png"),
          text: '我的盘库',
          url: '/pages/inventorydaily/inventorydaily'
        }
      ],
      list2: [
        // {
        //   img: require("../assets/check.png"),
        //   text: '待审核',
        //   url: `/pages/advanceorder/advanceorder?active=${0}`,
        //   number: 0
        // },
        //   {
        //     img: require("../assets/examine.png"),
        //     text: '待验车',
        //     url: `/pages/advanceorder/advanceorder?active=${1}`,
        //     number: 0
        //   },
          // {
          //   img: require("../assets/order.png"),
          //   text: '待确认',
          //   url: `/pages/advanceorder/advanceorder?active=${2}`,
          //   number: 0
          // },
          // {
          //   img: require("../assets/end.png"),
          //   text: '已完结',
          //   url: `/pages/advanceorder/advanceorder?active=${3}`,
          //   number: 0
          // },
        {
          img: require("../assets/check.png"),
          text: '待审核',
          url: `/pages/advanceorderList?active=${0}`,
          number: 0
        },
        {
          img: require("@/assets/images/pass.png"),
          text: '审核通过',
          url: `/pages/advanceorderList?active=${1}`,
          number: 0
        },
        {
          img: require("@/assets/images/nopass.png"),
          text: '审核不通过',
          url: `/pages/advanceorderList?active=${2}`,
          number: 0
        },
      ],
      list3: [
        // {
        //     img: require("../assets/check.png"),
        //     text: '待审核',
        //     url: `/pages/financingorder/financingorder?active=${0}`,
        //     number: 0
        // },
        // {
        //     img: require("../assets/examine.png"),
        //     text: '待验车',
        //     url: `/pages/financingorder/financingorder?active=${1}`,
        //     number: 0
        // },
        // {
        //     img: require("../assets/order.png"),
        //     text: '待确认',
        //     url: `/pages/financingorder/financingorder?active=${2}`,
        //     number: 0
        // },
        // {
        //     img: require("../assets/end.png"),
        //     text: '已完结',
        //     url: `/pages/financingorder/financingorder?active=${3}`,
        //     number: 0
        // }
      ],
      item: {},
      stocktakingNum: 0
    }
  }
  componentWillMount() {
    this.upappInfo()
    this.getOrderHandle()
    this.myInfo()
  }

  componentDidShow() {
    sdk.setTitleInfo(this.state.title)
  }

  async myInfo() {
    const { stocktakingNum } = await http.myInfo()
    this.setState({ stocktakingNum })
  }
  upappInfo() {
    http.upappInfo().then(res => {
      let { list1 } = this.state
      list1[0].url = `/pages/advanceform/advanceform?type=usercar&AvailableQuota=${res.mqAmAvailableQuota || 0}`
      this.setState({
        item: res,
        list1
      })
    })
  }
  applyHandle() {
    let { item } = this.state
    // function getValue(status) {
    //     return {
    //         $undefined: 0
    //         $:0
    //     }[`$${status}`]
    // }
    Taro.navigateTo({
      url: `/pages/advancefundform/advancefundform?id=${item.id}&mqAmQuota=${item.mqAmQuota || 0}&mqAmAvailableQuota=${item.mqAmAvailableQuota || 0}`
    })
  }

  onActiveHandle(url) {
    Taro.navigateTo({
      url
    })
  }

  getOrderHandle() {
    // http.getOrderNumber().then(({ data }) => {
    //     debugger
    // })
  }



  render() {
    const { title, list1, list2, list3, item, stocktakingNum } = this.state
    return (
      <View className="b_advancefund">
        <Image src={bgImages} className='b_advancefund__images'></Image>
        <DNavBar title={title} className='b_advancefund__nav'></DNavBar>
        <View className="b_advancefund__box">
          <View className='b_advancefund__header'>
            <View className='b_advancefund__header_left'>
              <View className='b_advancefund__header_left__title'>可用代购额度</View>
              <View className='b_advancefund__header_left__money'>{item.mqAmAvailableQuota || '---万元'}
                {item.mqAmAvailableQuota && <Text className='item_money__text'>万元</Text>
                }
              </View>
              <View className='b_advancefund__header_left__total'>代购总额度<Text className='item_total__first'>{item.mqAmQuota || '---万元'}</Text>{item.mqAmQuota && <Text className='item_total__secode'>万元</Text>}</View>
            </View>
            <View className='b_advancefund__header_right' onClick={this.applyHandle.bind(this)}>提升额度</View>

          </View>
          <View className="b_advancefund__content">
            <View className='b_advancefund__content_title'>代购服务</View>
            <View className='b_advancefund__content_box'>
              {
                list1 && list1.map((item, i) => {
                  return <View className={['b_advancefund__list', stocktakingNum > 0 ? 'b_advancefund_server': ''].join(' ')} data-num={stocktakingNum} key={i} onClick={this.onActiveHandle.bind(this, item.url)}>
                    <Image src={item.img} className='b_advancefund__list_img'></Image>
                    <View className='b_advancefund__list_text'>{item.text}</View>
                  </View>
                })
              }
            </View>
          </View>
          <View className="b_advancefund__content">
            <View className='b_advancefund__content_title'>代购订单</View>
            <View className='b_advancefund__content_box'>
              {
                list2 && list2.map((item, i) => {
                  return <View className='b_advancefund__content-listbox'>
                    {
                      item.number > 0 && <Text className='b_advancefund__content-text'>{item.number > 99 ? '99+' : item.number}</Text>
                    }
                    <View className='b_advancefund__list' key={i} onClick={this.onActiveHandle.bind(this, item.url)}>
                      <Image src={item.img} className='b_advancefund__list_img'></Image>
                      <View className='b_advancefund__list_text'>{item.text}</View>
                    </View>
                  </View>
                })
              }
            </View>
          </View>
          {/* <View className="b_advancefund__content"> */}
            {/*<View className='b_advancefund__content_title'>库融订单</View>
              <View className='b_advancefund__content_box'>
                  {
                      list3 && list3.map((item, i) => {
                          return <View className='b_advancefund__content-listbox'>
                              {
                                  item.number > 0 && <Text className='b_advancefund__content-text'>{item.number > 99 ? '99+' : item.number}</Text>
                              }
                              <View className='b_advancefund__list' key={i} onClick={this.onActiveHandle.bind(this, item.url)}>
                                  <Image src={item.img} className='b_advancefund__list_img'></Image>
                                  <View className='b_advancefund__list_text'>{item.text}</View>
                              </View>
                          </View>
                      })
                  }
              </View>*/}
          {/* </View> */}
        </View>
      </View>
    )
  }
}
